<?php

namespace app\admin\model;

use app\common\model\BaseModel;


class Equity extends BaseModel
{

    

    

    // 表名
    protected $name = 'equity';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'status_text',
        'channel_text',
        'user_info_text'
    ];
    

    
    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4')];
    }

    public function getChannelList()
    {
        return ['0' => __('Channel 0'), '1' => __('Channel 1'), '2' => __('Channel 2')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getChannelTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['channel']) ? $data['channel'] : '');
        $list = $this->getChannelList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getUserInfoTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_id']) ? $data['order_id'] : '');
        $order =Order::where('id',$value)->find();
        if(!$order){
            return'';
        }
        $userinfo=User::where('id',$order->user_id)->field('username,mobile')->find();
        return isset($userinfo) ? $userinfo : '';
    }
    
   /**
     * 查询多条数据（分页）
     *
     * @param array $where
     * @param integer $pagesize
     * @param string $orderby
     * @param string $field
     * @return void
     */
    public function getSelect(array $where,$pagesize=20,$orderby='id desc',$field='*'){
        return $this->where($where)->order($orderby)->field($field)->paginate($pagesize);
    }



}
